package com.moji.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.moji.common.entity.MyPage;
import com.moji.common.utils.PageUtil;
import com.moji.entity.MjFlow;
import com.moji.entity.dto.QueryFlowDto;
import com.moji.mapper.MjFlowMapper;
import com.moji.service.MjFlowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 流程配置表 服务实现类
 * </p>
 *
 * @author ccl
 * @since 2024-07-27
 */
@Service
public class MjFlowServiceImpl extends ServiceImpl<MjFlowMapper, MjFlow> implements MjFlowService {

    @Override
    public MyPage<MjFlow> queryByPage(QueryFlowDto dto) {
        LambdaQueryWrapper<MjFlow> wrapper = new LambdaQueryWrapper<>();
        //状态
        wrapper.like(ObjectUtil.isNotEmpty(dto.getAuditStatus()),MjFlow::getAuditStatus
                ,dto.getAuditStatus());
        //创建时间倒叙
        wrapper.orderByDesc(MjFlow::getCreateTime);
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<MjFlow> mjFlows = list(wrapper);
        PageInfo<MjFlow> info = new PageInfo<>(mjFlows);
        return PageUtil.PageInfo2MyPage(info);
    }

    @Override
    public MjFlow detail(Long id) {
        MjFlow mjFlow=this.getById(id);
        if(mjFlow ==null){
            throw new RuntimeException("审批流程不存在,请核查!");
        }
        return mjFlow;
    }
}
